<template>
  <div>
    <WSelector :data="data" @selectChange="settargetId" />
    <div class="transfer">
      <ListItem :title="leftTitle" :listData="leftListData" leftOrRight="left" @addCheckedData="addCheckedData"
        @removeCheckedData="removeCheckedData"></ListItem>
      <div class="box w-btn">
        <button :disabled="isDisablLeftBtn" @click="removeRightListData(checkedData['right'])">&lt;</button>
        <button :disabled="isDisablRightBtn" @click="addRighetListData(checkedData['left'])">&gt;</button>
      </div>
      <ListItem :title="rightTitle" :listData="rightListData" leftOrRight="right" @addCheckedData="addCheckedData"
        @removeCheckedData="removeCheckedData"></ListItem>
    </div>
  </div>
</template>

<script setup>
import WSelector from './components/WSelector.vue';
import ListItem from './components/ListItem.vue';
import _props from './extends/props';
import { usetargetId, useRightListData, useComponentData, useCheckedData } from './extends/hooks';
const { data, rightTitle } = defineProps(_props);
const { targetId, settargetId } = usetargetId(10);
const { checkedData, addCheckedData, removeCheckedData } = useCheckedData();
const { rightListData, addRighetListData, removeRightListData } =
  useRightListData([], checkedData);
const { leftTitle, leftListData, isDisablLeftBtn, isDisablRightBtn } =
  useComponentData(data, targetId, rightListData, checkedData);

</script>
<style lang='scss' scoped>
.transfer {
  display: flex;
  align-items: center;
  width: 360px;
  height: 360px;
  border: 1px solid #ccc;
  border-radius: 5px;

  .w-btn {
    display: flex;
    justify-content: center;
    align-items: center;
    width: 120px;
    height: 100%;

    button {
      width: 40px;
      height: 30px;
      border: none;
      outline: none;
      background-color: orange;
      border-radius: 5px;
      color: #fff;

      &:nth-child(2) {
        margin-left: 20px;
      }

      // &:active {
      //   background-color: rgb(255, 165, 0, 0.5);
      //   color: rgb(255, 255, 255, 0.5);
      // }

      &:disabled {
        opacity: .5;
        cursor: no-drop;
      }
    }
  }
}
</style>